#—*—coding:utf-8 -*-
#@Time        :2022/7/16 19:26
#@Author      :dhx
#@File        :station_renwu_page.py
# @Software: PyCharm
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from pages.base_pageage import BasePage

class AddDuty(BasePage):
    url="http://192.168.3.133/crm/index.php?m=task&a=add"
    topic_locatior = (By.ID, 'subject')  # 主题
    person_locator = (By.ID, 'owner_name')  # 负责人
    option_person_locator = (By.XPATH, '//*[@id="ta1"]/span[1]/input')  # 勾选第一个
    ok_locator = (By.CSS_SELECTOR, 'body > div:nth-child(12) > '
                                   'div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)')

    related_locator = (By.ID, 'about_roles_name')
    first_locator = (By.XPATH, '//*[@id="ta1"]/span[1]/input')  # 勾选第一个
    ok_two_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]/span')  # ok选项
    option_relate_locator = (By.ID, 'select1')  # 选择相关
    input_locator = (By.ID, 'module_name')  # 相关后面的框
    customer_locator = (
        By.CSS_SELECTOR, '#datas > tr > td:nth-child(1) > input[type=radio]:nth-child(1)')  # 选择第一个客户
    save_locator = (By.XPATH, '/html/body/div[11]/div[3]/div/button[1]/span')  # 保存
    state_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[2]/select')  # 选择状态
    end_locatr = (By.ID, 'due_date')  # 截止日期
    grade_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[4]/select')  # 状态
    desc_locator = (By.XPATH, '/html/body')  # 描述
    keep_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')  # 点击保存
    def inpu_name(self):
        """输入主题"""
        self.driver.find_element(*self.topic_locatior).send_keys("主题")

    def option_person(self):
        """选择负责人"""
        self.driver.find_element(*self.person_locator).click()
        sleep(1)
    def first_person(self):
        """勾选第一个"""
        self.driver.find_element(*self.option_person_locator).click()
        sleep(1)
    def click_ok(self):
        """点击ok"""
        self.driver.find_element(*self.ok_locator).click()
        sleep(1)
    def click_relate(self):
        """点击相关"""
        self.driver.find_element(*self.related_locator).click()
        sleep(1)
    def first_relate(self):
        """勾选第一个"""
        self.driver.find_element(*self.first_locator).click()
        sleep(1)
    def ok_second(self):
        """确定"""
        self.driver.find_element(*self.ok_two_locator).click()
        sleep(1)
    def select_option(self):
        """下拉框选择"""
        select_locator = self.driver.find_element(* self.option_relate_locator)
        select = Select(select_locator)
        select.select_by_index(2)
    def input_relate(self):
        """相关后面的框"""
        self.driver.find_element(*self.input_locator).click()
        sleep(1)
    def customer_op(self):
        """勾选客户"""
        self.driver.find_element(*self.customer_locator).click()
        sleep(1)
    def save_duty(self):
        """点击保存"""
        self.driver.find_element(*self.save_locator).click()
        sleep(1)
    def status_duty(self):
        """选择状态"""
        state = self.driver.find_element(*self.state_locator)
        select = Select(state)
        select.select_by_index(1)
        sleep(1)
    def end_date(self):
        """输入截止日期"""
        self.driver.find_element(*self.end_locatr).send_keys("2022-07-01")
        sleep(1)
    def desc_duty(self):
        """输入描述"""
        self.driver.switch_to.frame(0)
        self.driver.find_element(*self.desc_locator).send_keys("描述")
        sleep(1)
    def end_duty(self):
        """点击保存"""
        self.driver.switch_to.default_content()
        self.driver.find_element(*self.keep_locator).click()
        sleep(1)
